package net.sudot.flow.dsl.model;

import net.sudot.flow.utils.GroovyExecuteUtils;
import groovy.lang.Closure;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * 流程
 *
 * @author tangjialin on 2020-03-13.
 */
@Getter
@Setter
@Accessors(chain = true)
public class Flow extends AbstractObject {
    private Closure<Object> pre;
    private Closure<Object> check;
    private Closure<Object> result;
    private Closure<Object> after;
    private Map<String, Send> sends = new HashMap<>();

    public void send(Object name, Closure<?> closure) {
        String key = name.toString();
        if (sends.containsKey(key)) {
            throw new IllegalArgumentException("重复的 send 对象:" + key);
        }
        Send send = new Send();
        GroovyExecuteUtils.configureObjectWithClosure(closure, send);
        sends.put(key, send);
    }
}
